package
{
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	
	public class Regular extends Sprite
	{
		
		public function Regular()
		{
			//target_global();
			//target_match();
			//target_metaChar();
			//target_tabs();
			//target_tabs_ex();
			//target_character();
			//target_character_ex1();
			//target_character_ex2();
			//target_character_ex3();
			//target_dot();
			//target_dot_ex();
			//target_select();
			//target_kuohao();
			target_kuohao_ex();
		}
		
		private function target_global():void
		{
			var string1:String = "windows is a excellent opreation system,I like windows";
			var str:RegExp = /windows/;
			var strg:RegExp = /windows/g;
			//  /g 是 global
			var repStr:String = "Linux";
			trace(string1.replace(str,repStr)); //output:Linux is a excellent opreation system,I like windows
			trace(string1.replace(strg,repStr)); //output:Linux is a excellent opreation system,I like Linux
		}
		
		private function target_match():void
		{
			var string2:String = "There is a computer at foo.room";
			var str1:RegExp = /a/;
			var str2:RegExp = /com/;
			var str3:RegExp = /a computer/;
			var str4:RegExp = /lalala/;
			
			trace(string2.match(str1)); //output a
			trace(string2.match(str2)); //output com
			trace(string2.match(str3)); //output a computer
			trace(string2.match(str4)); //null
		}
		
		private function target_metaChar():void
		{
			//元字符   11个   []\^$.|?*+()
			var string3:String = "lxtobe5@qq.com";
			var str1:RegExp = /@/g;
			var str2:RegExp = /\./g;
			trace(string3.match(str1));  //output  @
			trace(string3.match(str1).length);  //output  1
			trace(string3.match(str2));  //output  .
			trace(string3.match(str2).length);  //output  1
		}
		
		/*
		不可见字符
		\cx匹配有ｘ指明的控制字符。例如\cM匹配一个Control-M或回车符。x的值必须为A~Z或a~z之一。否则将c视为一个原义的'c'字符
		\f匹配一个换页符。等价于\x0c和\cL
		\n匹配一个换行符。等价于\x0a和\cJ
		\r匹配一个回车符。等价于\x0d和\cM
		\s匹配任何空白字符，包括空格、制表符、换页符等等。等价于[\f\n\r\t\v]
		\S匹配任何非空白字符，等价于[^\f\n\r\t\v]
		\t匹配一个制表符，等价于\x09和\cI
		\v匹配一个垂直制表符，等价于\x0b和\cK
		*/
		
		private function target_tabs():void
		{
			var string4:String = "There is a \t computer \t at foo.com \t";
			var str1:RegExp = /\t/g;  //output  There is a 	 computer 	 at foo.com 	
			trace(string4);
			trace(string4.match(str1));  //output	,	,	//由于制表符不可见，所以输出3个空白，由逗号隔开
			trace(string4.match(str1).length);  //output  3
		}
		
		private function target_tabs_ex():void
		{
			var string5:String = "computer complete com abc.com \tcom \rcom notcome";  // \r换行符
			var str1:RegExp = /\scom\s/g;  // \s表示任意空白字符
			trace(string5.match(str1));  /*output   com ,	com ,
			                                        com */
			trace(string5.match(str1).length);  //output 3
		}
		
		private function target_character():void
		{
			var string6:String = "geteet got asdfget geot adgotdd get ter gxt"; // []将字符包住
			var str1:RegExp = /\sg[eo]t\s/g;
			trace(string6.match(str1));  //output  got , get 
			trace(string6.match(str1).length);  //output  2    //注意geot没有被匹配，因为字符集只匹配一个
		}
		
		private function target_character_ex1():void
		{
			var string7:String = "2011/12/25 2012-12-25 12/25/2013 25/12/2014";
			var str1:RegExp = /[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]/g;
			trace(string7.match(str1));  //output  25/12/2014
		}
		
		private function target_character_ex2():void
		{
			var string8:String = "0bEE 0xff 0x09 0x2e";
			var str1:RegExp = /0x[A-F0-9][a-f0-9]/g;
			trace(string8.match(str1));  //output  0x09,0x2e
		}
		
		private function target_character_ex3():void
		{
			var string9:String = "gt get got g t gtt gst geet";
			var str1:RegExp = /g[^eo]t/g;  // ^取反，只要不是该字符的字符（包括空白字符）都匹配，但不能匹配空的字符
			var str2:RegExp = /g[e^o]t/g;  // ^不紧跟[，将没有取反作用
			trace(string9.match(str1));  //output  g t,gtt,gst
			trace(string9.match(str2));  //output  get,got
		}
		
		private function target_dot():void
		{
			var string10:String = "g5t g\nt g\rt g-t gtt gst seet";
			var str1:RegExp = /g.t/sg;  // s为单行标签
			trace(string10.match(str1));
			/*output
			g5t,g    // .不能匹配\n 但是加s单行标签可以让.匹配新行符
			t,g
			t,g-t,gtt,gst
			*/
		}
		
		private function target_dot_ex():void
		{
			var string11:String = "<1> |2| (3) -4- $5* c6d 2advance 想1想";
			var str1:RegExp = /.[0-9]./sg;
			var str2:RegExp = /[(-<][0-9][(-[<]/g;
			trace(string11.match(str1));  //output  <1>,|2|,(3),-4-,$5*,c6d, 2a,想1想
			trace(string11.match(str2));  //output  <1>,(3),-4-
		}
		
		private function target_select():void
		{
			var string12:String = "he saw the truth. I see it.";
			var str1:RegExp = /saw|see/g;
			var str2:RegExp = /\ssaw|see\s/g;
			var str3:RegExp = /\s(saw|see)\s/g;
			trace(string12.match(str1));  //output  saw,see
			trace(string12.match(str2));  //output   saw,see  // |作用范围选择的是\ssaw和see\s
			trace(string12.match(str3));  //output   saw , see  // 用()控制选择范围
		}
		
		private function target_kuohao():void
		{
			var string13:String = "kkasdf ksdfs kkkadd xkkacc kkkkadfsd";
			var str1:RegExp = /k{2}a/;
			var str2:RegExp = /k{3,}a/;
			var str3:RegExp = /k{1,3}a/;
			var str4:RegExp = /k*/;   //k重复0次或多次      等价/k{0,}/
			var str5:RegExp = /k+/;   //k重复1次或多次      等价/k{1,}/
			var str6:RegExp = /k?/;   //k重复0次或1次        等价/k{0,1}/
			trace(string13.match(str1));  //output  kka   //k重复2次
			trace(string13.match(str2));  //output  kkka  //k至少重复3次
			trace(string13.match(str3));  //output  kka   //k至少重复1到3次
			trace(string13.match(str4));  //output  kk
			trace(string13.match(str5));  //output  kk
			trace(string13.match(str6));  //output  k
		}
		
		private function target_kuohao_ex():void
		{
			var string14:String = "asdgle google googoogle googlegoogle";
			var str1:RegExp = /g[eo]*gle/g;  
			var str2:RegExp = /(goo)*gle/g;  
			trace(string14.match(str1));   //output  google,google,google,google
			trace(string14.match(str2));   //output  gle,google,googoogle,google,google
		}
	}
}